<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Account extends CI_Controller {
	//protected $head;
	public function __construct()
	{
		parent::__construct();
		//$this->head="我是头部";
		$this->load->model('Blogs','bg');
	}
	public function register()
	{
		//echo site_url();
		$head="晚上";
		//global $CI;
		//$CI->init="我是刘月飞";
		//print_r($CI);
		$this->load->view('Account/register');
	}
	public function do_register()
	{
		$ajax['status']=1;
		$this->load->model('Accounts');
		
		$data['user_name']=$_POST['username'];
		//判断用户名是否唯一
		if(!$this->Accounts->usernameIsUnique($data['user_name'])){
			$ajax['status']=0;
			$ajax['msg']="用户名已被使用";
			echo json_encode($ajax);die();
		}
		
		$data['email']=$_POST['email'];
		//判断邮箱是否唯一
		if(!$this->Accounts->emailIsUnique($data['email'])){
			$ajax['status']=0;
			$ajax['msg']="邮箱已被使用";
			echo json_encode($ajax);die();
		}
		
		$data['mobile']=$_POST['mobile'];
		//判断手机号是否唯一
		if(!$this->Accounts->mobileIsUnque($data['mobile'])){
			$ajax['status']=0;
			$ajax['msg']="手机号已被使用";
			echo json_encode($ajax);die();
		}
		
		$data['password']=$_POST['password'];
		//判断两次密码是否相同
		if($data['password']!=$_POST['password2']){
			$ajax['status']=0;
			$ajax['msg']="两次密码不相同";
			echo json_encode($ajax);die();
		}
		
		$data['registor_time']=time();
		$this->Accounts->registor($data);
		
		//重定向
		$this->load->helper('url');
		redirect('Home/index/index');
		//echo json_encode($ajax);
	}
}
